#-*- coding: utf-8 -*-
from django.core.mail import send_mail
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
#from django.core.context_processors import csrf
from mysite.contact.forms import ContactForm

def contact(request):
    if request.method == 'POST':
#        c = {}
#        c.update(csrf(request))
        form = ContactForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            send_mail(
                cd['subject'],
                cd['message'],
                cd.get('email', 'noreply@example.com'),
                ['thebestzorro@ya.ru'],
            )
            return HttpResponseRedirect('/contact/')
    else:
        form = ContactForm(initial={'subject': u'привет'})
    return render_to_response('contact_form.html', {'form': form})
